﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;

namespace CodeBuilder
{
    public static class CommonHelper
    {
        /// <summary>
        /// 首字母小写写
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string FirstCharToLower(this string input)
        {
            if (String.IsNullOrEmpty(input))
                return input;
            string str = input.First().ToString().ToLower() + input.Substring(1);
            return str;
        }

        /// <summary>
        /// 首字母大写
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string FirstCharToUpper(this string input)
        {
            if (String.IsNullOrEmpty(input))
                return input;
            string str = input.First().ToString().ToUpper() + input.Substring(1);
            return str;
        }

        /// <summary>
        /// 返回短横线连接
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string ToHyphenate(this string input)
        {
            if (String.IsNullOrEmpty(input))
                return input;
            var strList = new List<char>();
            strList.Add(input.First());

            var lastCharArray = input.Substring(1).ToCharArray();
            foreach (var c in lastCharArray)
            {
                if (c > 'A' && c < 'Z')
                    strList.Add('-');
                strList.Add(c);
            }
            return string.Join("",strList.ToArray()).ToLower();
        }
    }
}
